<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/smart_ptr/detail</a> - sp_counted_base_gcc_x86.hpp<span style="font-size: 80%;"> (source / <a href="sp_counted_base_gcc_x86.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">15</td>
            <td class="headerCovTableEntry">18</td>
            <td class="headerCovTableEntryMed">83.3 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_X86_HPP_INCLUDED</a>
<span class="lineNum">       2 </span>            : #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_X86_HPP_INCLUDED
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : // MS compatible compilers support #pragma once
<span class="lineNum">       5 </span>            : 
<span class="lineNum">       6 </span>            : #if defined(_MSC_VER) &amp;&amp; (_MSC_VER &gt;= 1020)
<span class="lineNum">       7 </span>            : # pragma once
<span class="lineNum">       8 </span>            : #endif
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : //
<span class="lineNum">      11 </span>            : //  detail/sp_counted_base_gcc_x86.hpp - g++ on 486+ or AMD64
<span class="lineNum">      12 </span>            : //
<span class="lineNum">      13 </span>            : //  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
<span class="lineNum">      14 </span>            : //  Copyright 2004-2005 Peter Dimov
<span class="lineNum">      15 </span>            : //
<span class="lineNum">      16 </span>            : //  Distributed under the Boost Software License, Version 1.0. (See
<span class="lineNum">      17 </span>            : //  accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">      18 </span>            : //  http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">      19 </span>            : //
<span class="lineNum">      20 </span>            : //
<span class="lineNum">      21 </span>            : //  Lock-free algorithm by Alexander Terekhov
<span class="lineNum">      22 </span>            : //
<span class="lineNum">      23 </span>            : //  Thanks to Ben Hitchings for the #weak + (#shared != 0)
<span class="lineNum">      24 </span>            : //  formulation
<span class="lineNum">      25 </span>            : //
<span class="lineNum">      26 </span>            : 
<span class="lineNum">      27 </span>            : #include &lt;boost/detail/sp_typeinfo.hpp&gt;
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            : namespace boost
<span class="lineNum">      30 </span>            : {
<span class="lineNum">      31 </span>            : 
<span class="lineNum">      32 </span>            : namespace detail
<span class="lineNum">      33 </span>            : {
<span class="lineNum">      34 </span>            : 
<span class="lineNum">      35 </span>            : inline int atomic_exchange_and_add( int * pw, int dv )
<span class="lineNum">      36 </span>            : {
<span class="lineNum">      37 </span>            :     // int r = *pw;
<span class="lineNum">      38 </span>            :     // *pw += dv;
<span class="lineNum">      39 </span>            :     // return r;
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            :     int r;
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span>            :     __asm__ __volatile__
<span class="lineNum">      44 </span>            :     (
<span class="lineNum">      45 </span>            :         &quot;lock\n\t&quot;
<span class="lineNum">      46 </span>            :         &quot;xadd %1, %0&quot;:
<span class="lineNum">      47 </span>            :         &quot;=m&quot;( *pw ), &quot;=r&quot;( r ): // outputs (%0, %1)
<span class="lineNum">      48 </span>            :         &quot;m&quot;( *pw ), &quot;1&quot;( dv ): // inputs (%2, %3 == %1)
<span class="lineNum">      49 </span>            :         &quot;memory&quot;, &quot;cc&quot; // clobbers
<span class="lineNum">      50 </span><span class="lineCov">        937 :     );</span>
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span>            :     return r;
<span class="lineNum">      53 </span>            : }
<span class="lineNum">      54 </span>            : 
<span class="lineNum">      55 </span>            : inline void atomic_increment( int * pw )
<span class="lineNum">      56 </span>            : {
<span class="lineNum">      57 </span>            :     //atomic_exchange_and_add( pw, 1 );
<span class="lineNum">      58 </span>            : 
<span class="lineNum">      59 </span>            :     __asm__
<span class="lineNum">      60 </span>            :     (
<span class="lineNum">      61 </span>            :         &quot;lock\n\t&quot;
<span class="lineNum">      62 </span>            :         &quot;incl %0&quot;:
<span class="lineNum">      63 </span>            :         &quot;=m&quot;( *pw ): // output (%0)
<span class="lineNum">      64 </span>            :         &quot;m&quot;( *pw ): // input (%1)
<span class="lineNum">      65 </span>            :         &quot;cc&quot; // clobbers
<span class="lineNum">      66 </span><span class="lineCov">        476 :     );</span>
<span class="lineNum">      67 </span>            : }
<span class="lineNum">      68 </span>            : 
<span class="lineNum">      69 </span>            : inline int atomic_conditional_increment( int * pw )
<span class="lineNum">      70 </span>            : {
<span class="lineNum">      71 </span>            :     // int rv = *pw;
<span class="lineNum">      72 </span>            :     // if( rv != 0 ) ++*pw;
<span class="lineNum">      73 </span>            :     // return rv;
<span class="lineNum">      74 </span>            : 
<span class="lineNum">      75 </span>            :     int rv, tmp;
<span class="lineNum">      76 </span>            : 
<span class="lineNum">      77 </span>            :     __asm__
<span class="lineNum">      78 </span>            :     (
<span class="lineNum">      79 </span>            :         &quot;movl %0, %%eax\n\t&quot;
<span class="lineNum">      80 </span>            :         &quot;0:\n\t&quot;
<span class="lineNum">      81 </span>            :         &quot;test %%eax, %%eax\n\t&quot;
<span class="lineNum">      82 </span>            :         &quot;je 1f\n\t&quot;
<span class="lineNum">      83 </span>            :         &quot;movl %%eax, %2\n\t&quot;
<span class="lineNum">      84 </span>            :         &quot;incl %2\n\t&quot;
<span class="lineNum">      85 </span>            :         &quot;lock\n\t&quot;
<span class="lineNum">      86 </span>            :         &quot;cmpxchgl %2, %0\n\t&quot;
<span class="lineNum">      87 </span>            :         &quot;jne 0b\n\t&quot;
<span class="lineNum">      88 </span>            :         &quot;1:&quot;:
<span class="lineNum">      89 </span>            :         &quot;=m&quot;( *pw ), &quot;=&amp;a&quot;( rv ), &quot;=&amp;r&quot;( tmp ): // outputs (%0, %1, %2)
<span class="lineNum">      90 </span>            :         &quot;m&quot;( *pw ): // input (%3)
<span class="lineNum">      91 </span>            :         &quot;cc&quot; // clobbers
<span class="lineNum">      92 </span><span class="lineNoCov">          0 :     );</span>
<span class="lineNum">      93 </span>            : 
<span class="lineNum">      94 </span>            :     return rv;
<span class="lineNum">      95 </span>            : }
<span class="lineNum">      96 </span>            : 
<span class="lineNum">      97 </span>            : class sp_counted_base
<span class="lineNum">      98 </span>            : {
<span class="lineNum">      99 </span>            : private:
<span class="lineNum">     100 </span>            : 
<span class="lineNum">     101 </span>            :     sp_counted_base( sp_counted_base const &amp; );
<span class="lineNum">     102 </span>            :     sp_counted_base &amp; operator= ( sp_counted_base const &amp; );
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span>            :     int use_count_;        // #shared
<span class="lineNum">     105 </span>            :     int weak_count_;       // #weak + (#shared != 0)
<span class="lineNum">     106 </span>            : 
<span class="lineNum">     107 </span>            : public:
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span><span class="lineCov">        232 :     sp_counted_base(): use_count_( 1 ), weak_count_( 1 )</span>
<span class="lineNum">     110 </span>            :     {
<span class="lineNum">     111 </span>            :     }
<span class="lineNum">     112 </span>            : 
<span class="lineNum">     113 </span>            :     virtual ~sp_counted_base() // nothrow
<span class="lineNum">     114 </span><span class="lineCov">        232 :     {</span>
<span class="lineNum">     115 </span>            :     }
<span class="lineNum">     116 </span>            : 
<span class="lineNum">     117 </span>            :     // dispose() is called when use_count_ drops to zero, to release
<span class="lineNum">     118 </span>            :     // the resources managed by *this.
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            :     virtual void dispose() = 0; // nothrow
<span class="lineNum">     121 </span>            : 
<a name="122"><span class="lineNum">     122 </span>            :     // destroy() is called when weak_count_ drops to zero.</a>
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span><span class="lineCov">        232 :     virtual void destroy() // nothrow</span>
<span class="lineNum">     125 </span>            :     {
<span class="lineNum">     126 </span><span class="lineCov">        232 :         delete this;</span>
<span class="lineNum">     127 </span><span class="lineCov">        232 :     }</span>
<span class="lineNum">     128 </span>            : 
<span class="lineNum">     129 </span>            :     virtual void * get_deleter( sp_typeinfo const &amp; ti ) = 0;
<span class="lineNum">     130 </span>            :     virtual void * get_untyped_deleter() = 0;
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span>            :     void add_ref_copy()
<span class="lineNum">     133 </span>            :     {
<span class="lineNum">     134 </span><span class="lineCov">        475 :         atomic_increment( &amp;use_count_ );</span>
<span class="lineNum">     135 </span>            :     }
<span class="lineNum">     136 </span>            : 
<span class="lineNum">     137 </span>            :     bool add_ref_lock() // true on success
<span class="lineNum">     138 </span>            :     {
<span class="lineNum">     139 </span><span class="lineNoCov">          0 :         return atomic_conditional_increment( &amp;use_count_ ) != 0;</span>
<a name="140"><span class="lineNum">     140 </span>            :     }</a>
<span class="lineNum">     141 </span>            : 
<span class="lineNum">     142 </span><span class="lineCov">        706 :     void release() // nothrow</span>
<span class="lineNum">     143 </span>            :     {
<span class="lineNum">     144 </span><span class="lineCov">       1412 :         if( atomic_exchange_and_add( &amp;use_count_, -1 ) == 1 )</span>
<span class="lineNum">     145 </span>            :         {
<span class="lineNum">     146 </span><span class="lineCov">        231 :             dispose();</span>
<span class="lineNum">     147 </span>            :             weak_release();
<span class="lineNum">     148 </span>            :         }
<span class="lineNum">     149 </span><span class="lineCov">        706 :     }</span>
<span class="lineNum">     150 </span>            : 
<span class="lineNum">     151 </span>            :     void weak_add_ref() // nothrow
<span class="lineNum">     152 </span>            :     {
<span class="lineNum">     153 </span><span class="lineCov">          1 :         atomic_increment( &amp;weak_count_ );</span>
<span class="lineNum">     154 </span>            :     }
<span class="lineNum">     155 </span>            : 
<span class="lineNum">     156 </span>            :     void weak_release() // nothrow
<span class="lineNum">     157 </span>            :     {
<span class="lineNum">     158 </span><span class="lineCov">        462 :         if( atomic_exchange_and_add( &amp;weak_count_, -1 ) == 1 )</span>
<span class="lineNum">     159 </span>            :         {
<span class="lineNum">     160 </span><span class="lineCov">        231 :             destroy();</span>
<span class="lineNum">     161 </span>            :         }
<span class="lineNum">     162 </span>            :     }
<span class="lineNum">     163 </span>            : 
<span class="lineNum">     164 </span>            :     long use_count() const // nothrow
<span class="lineNum">     165 </span>            :     {
<span class="lineNum">     166 </span><span class="lineNoCov">          0 :         return static_cast&lt;int const volatile &amp;&gt;( use_count_ );</span>
<span class="lineNum">     167 </span>            :     }
<span class="lineNum">     168 </span>            : };
<span class="lineNum">     169 </span>            : 
<span class="lineNum">     170 </span>            : } // namespace detail
<span class="lineNum">     171 </span>            : 
<span class="lineNum">     172 </span>            : } // namespace boost
<span class="lineNum">     173 </span>            : 
<span class="lineNum">     174 </span>            : #endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_X86_HPP_INCLUDED
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
